package com.xhh.nphm.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xhh.nphm.system.domain.KbmCateM;
import com.xhh.nphm.system.domain.KbmPointM;
import com.xhh.nphm.system.domain.NodeCate;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface KbmCateMDao extends BaseMapper<KbmCateM> {
    @Select(" select *" +
            " from kbmCateM " +
            " where IsDel = 0 and UseFlag = 1 [[ and CodePk = #{codepk}]] [[ and SortName =#{sortname}]]")
    List<KbmCateM> kbmCateListJson(KbmCateM kbmCate);

    @Select(" select CodePk id,CodeParent pid,SortName text,UseFlag state" +
            " from kbmCateM " +
            " where IsDel = 0 and UseFlag = 1")
    List<NodeCate> kbmCateList();

    @Select("select * from kbmCateM where UseFlag = 1 and CodePk = #{codePk}")
    KbmCateM findCateById(String codePk);

    @Update("update kbmCateM set IsDel = 1 where CodePk = #{codePk};")
    int removeCateByCodePk(String codePk);
    
    @Update("update kbmCateM set CodeParent = #{codeparent},LayerNum = #{layernum},SortName = #{sortname},OrdNum=#{ordnum},EndFlag=#{endflag},BringTime=#{bringtime} where CodePk = #{codepk};")
    int updateByCodePK(KbmCateM kbmCate);

    @Select("select count(1) from kbmCateM where CodeParent = #{codePk} and IsDel = 0")
    int selectCateByCodePk(String codePk);

    @Select("select * from kbmCateM where CodePk = #{codePk}")
    KbmCateM selectByCodePk(String codePk);

    @Select("select count(1) from kbmCateM where CodePk = #{codepk} and IsDel = 0")
    int checkCodePkUnique(KbmCateM kbmCate);

    @Select("select count(1) from kbmCateM where SortName = #{sortname,jdbcType=VARCHAR} and IsDel = 0")
    int checkSortNameUnique(KbmCateM kbmCate);
}
